--
-- Author: ping.wang
-- Date: 2019-05-08 16:26:16
--
-- PriceBidTipsPanel
--

local ClassRef = app.mvc.createPanelClass(...)
local paddingH = 25 --每添加一行的行间距
--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.PriceBidTipsPanel))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)

    self._ui["Panel/Panel_1/name"]:setString(L("guildwarlimit_string4"))
    self._ui["Panel/Panel_2/text_1"]:setString(L("guildwarlimit_string5"))
    local openServerDays = app.session:getMerageOpenDays() -- 开服第几天
    self._ui["Panel/Panel_3/text_1"]:setString(string.format(L("guildwarlimit_string6"),openServerDays))
    self._ui["Panel/Panel_4/time_tlt"]:setString(L("guildwarlimit_string8"))
    self._ui["Panel/Panel_4/num_tlt"]:setString(L("guildwarlimit_string9"))
    --读表来初始化说明
    local posX,posY = self._ui["Panel/Panel_5"]:getPosition()
    local anchorPoint = self._ui["Panel/Panel_5"]:getAnchorPoint()
    --local numPosX,numPosY = self._ui["Panel/Panel_5/num_tlt"]:getPosition()
    local forceLimitInfos = GD:getForceLimitInfos()
    local myOwnerLimitInfo = GD:getForceLimitInfoByDay(openServerDays)
    local addPaddingH = 0
    local totalLimitNum = #forceLimitInfos


    for k,v in ipairs(forceLimitInfos) do
        if k == 1 then
            --这么写默认肯定超过1行
            self._ui["Panel/Panel_5/time_tlt"]:setString(string.format(L("guildwarlimit_string10"),tostring(v.limitDay)))
            self._ui["Panel/Panel_5/num_tlt"]:setString(tostring(v.limitnum))

            if myOwnerLimitInfo.ID == v.ID then
                self._ui["Panel/Panel_5/time_tlt"]:setTextColor(cc.c3b(82,255,69))
                self._ui["Panel/Panel_5/num_tlt"]:setTextColor(cc.c3b(82,255,69))
            else
                self._ui["Panel/Panel_5/time_tlt"]:setTextColor(cc.c3b(183,183,183))
                self._ui["Panel/Panel_5/num_tlt"]:setTextColor(cc.c3b(183,183,183))
            end
        else
            addPaddingH = addPaddingH + paddingH
            local temp = self._ui["Panel/Panel_5"]:clone()
            temp:setAnchorPoint(anchorPoint)
            temp:setContentSize(self._ui["Panel/Panel_5"]:getContentSize())
            --这里这么写因为panel冲设置大小后位置会偏移
            temp:setPosition(posX,posY - addPaddingH + (totalLimitNum - 1) * paddingH)
            self._ui["Panel"]:addChild(temp)
            temp:findChild("num_tlt"):setAnchorPoint(cc.p(1,0.5))
            temp:findChild("num_tlt"):setPosition(290,15)
            if checknumber(v.limitnum) == 0 then
                temp:findChild("time_tlt"):setString(string.format(L("guildwarlimit_string11"),tostring(v.limitDay)))
                temp:findChild("num_tlt"):setString(L("guildwarlimit_string12"))
            else
                temp:findChild("time_tlt"):setString(string.format(L("guildwarlimit_string10"),tostring(v.limitDay)))
                temp:findChild("num_tlt"):setString(tostring(v.limitnum))
            end

            if myOwnerLimitInfo.ID == v.ID then
                temp:findChild("time_tlt"):setTextColor(cc.c3b(82,255,69))
                temp:findChild("num_tlt"):setTextColor(cc.c3b(82,255,69))
            else
                temp:findChild("time_tlt"):setTextColor(cc.c3b(183,183,183))
                temp:findChild("num_tlt"):setTextColor(cc.c3b(183,183,183))
            end
        end
    end

    local size = self._ui.Panel:getContentSize()
    self._ui.Panel:setContentSize(cc.size(size.width, size.height + addPaddingH ))
    ccui.Helper:doLayout(self._ui.Panel)
    self:setContentSize( self._ui.Panel:getContentSize() )
end

function ClassRef:onOperate(cb)
    self._onOperate = cb
end

return ClassRef
